/*	
	This program is free software; you can redistribute it and/or modify 
	it under the terms of the GNU General Public License as published by 
	the Free Software Foundation; either version 2 of the License, or 
	any later version.

    	This program is distributed in the hope that it will be useful, but 
	WITHOUT ANY WARRANTY; without even the implied warranty of 
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
	General Public License for more details.

    	You should have received a copy of the GNU General Public License 
	along with this program; if not, write to the Free Software 
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
	USA
*/

#include<interrupt.h>

struct table_irq {
		void (*handler)(void);
} irq[16];


void add_irq(int p,void (*handler)(void)) {
	irq[p].handler=handler;
}

void gestisci_irq(unsigned int esp) {
	char int_request,bit;
	int posizione;
	int i;

	posizione=0;
	out_port(0x20,0x0B);
	int_request=in_port(0x20);
	if(int_request==0) {
		out_port(0xA0,0x0B);
		int_request=in_port(0xA0);
		posizione=8;
	}
	for(i=0;i<8;i++) {
		bit=(int_request & (1 << i));
		if(bit!=0) { break; }
	}
	posizione=posizione+i;
	irq[posizione].handler();
/*
	if(posizione==0) {timer();}
	if(posizione==1) {input_tastiera();}*/
	if(posizione>=8) {out_port(0xA0,0x20);} 
	else {out_port(0x20,0x20);}
}
